<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use App\Models\Order;

class OrderController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        
        
        $db = \DB::table("order"); 
       //判断并封装搜索条件
       $params = array();
       if(!empty($_GET['name'])){
           $db->where("phone_code","like","%{$_GET['name']}%");
           $params['phone_code'] = $_GET['name']; //维持搜索条件
           
       }
       
       if(!empty($_GET['phone'])){
           $db->where("phone","like","%{$_GET['phone']}%");
           $params['phone'] = $_GET['phone']; //维持搜索条件
           
       }
       
       
       
      //  $users_id = $request->session()->get('user_id');
       
       // $city_id = DB::table('city')->select('id')->where('user_id',$users_id)->first();
        
        
        
      
         
         
        
        $list =$db->select('order.*','allusers.nickName')
                        ->leftJoin('allusers','order.openid','=','allusers.openid')
                      //  ->where('order.city_id',$city_id->id)
                        ->where('status',1)
                        ->orderBy('order.created_at','DESC')
                        ->paginate(5);
       
        
        return view('admin.order.index',['list'=>$list,'params'=>$params]);
        
    }
       
    public function swoole($id)
    {
        $status['status'] = 2;
        $info = \DB::table('order')->where('id',$id)->update($status);
        if($info>0){
            return $msg = '200';
         }else{
            return $msg = '000';
         }
    }
    
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
